import express from "express";
import {
  registerUser,
  authUser,
  getUserProfile,
  updateUserProfile,
  getUsers,
  deleteUser,
  getUserById,
  updateUserById,
} from "../controller/userController.js";
import { protect, admin } from "../middleware/auth.js";
const router = express.Router();

//用户注册
//获取所有用户
router.route("/").post(registerUser).get(protect, admin, getUsers);

//用户身份验证，获取token
router.post("/login", authUser);

//获取成功登录用户详情，私密路由需要token
//更新用户资料
router
  .route("/profile")
  .get(protect, getUserProfile)
  .put(protect, updateUserProfile);

//根据id删除用户
//根据id获取用户
//根据id更新用户
router
  .route("/:id")
  .delete(protect, admin, deleteUser)
  .get(protect, admin, getUserById)
  .put(protect, admin, updateUserById);

export default router;
